package hzjbbis.framework.workflow.util;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class ContextUtils {
    private static ContextUtils instance;
    private AbstractApplicationContext context;

    private ContextUtils() {
        try {
            Context ctx = new InitialContext();
            context = (AbstractApplicationContext) ctx
                .lookup("WebApplicationContext");
        } catch (NamingException e) {
        }

        if (context == null) {
            context = new ClassPathXmlApplicationContext(
                "/resources/applicationContext.xml");
        }        
    }
    
    public synchronized static ContextUtils getInstance() {
        if (instance == null) {
            instance = new ContextUtils();
        }
        return instance;
    }

    public AbstractApplicationContext getContext() {
        return context;
    }
}